<template>
	<view class="comment bg">
		<view class="top">
			<view class="top-l"><image :src="proDetail.commodityPicture" mode=""></image></view>
			<view class="top-r">{{proDetail.commodityName}}</view>
		</view>
		<view class="grade">
			<text class="iconfont icon-xingxing" size="36" v-for="(item, i) in 5" :class="{'colorG': i >= 5}" :key="i"></text>
			口碑好评
		</view>
		<view class="content">
			<textarea value="" placeholder="分享一下你对这件商品的使用心得吧。" />
		</view>
		<view class="upload">
			<view class="title">上传图片 <text>最多上传4张</text></view>
			<view class="img-list">
				<view class="img-item img" v-for="(item,i) in imageList" :key="i">
					<image :src="item" mode=""></image>
				</view>
				<view class="img-item" @click="addImg">
					+
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import Request from '../../../common/request.js'
	import {api} from '../../../common/api.js'
	export default {
		data() {
			return {
				orderId:'',
				commodityId:'',
				detailId:'',
				proDetail:'',
				imageList: [],
				countIndex: 3,
			};
		},
		onLoad(option) {
			this.orderId = option.orderId;
			this.commodityId = option.commodityId;
			this.detailId = option.detailId
			this.initData();
		},
		methods: {
			initData(){
				Request.fetchPost('/fsbus/M2217',{
					orderId: this.orderId,
					commodityId: this.commodityId,
					detailId: this.detailId
				}).then(res=>{
					if(res.errorNo == 0){
						this.proDetail = res.results.mCommodityBase
					}
				}).catch(err=>{})
			},
			addImg() {
				let self = this;
				uni.chooseImage({
					sourceType: ['camera', 'album'],
					sizeType: ['original', 'compressed'],
					count: 1,
					success: (res) => {
						const tempFilePaths = res.tempFilePaths;
						const uploadTask = uni.uploadFile({
							url : api+'/upload',
							filePath: tempFilePaths[0],
							name: 'file',
							dataType:'json',
							header:{
								'token': uni.getStorageSync('token')
							},
							success: function (res) {
								let data = JSON.parse(res.data)
								self.imageList.push(data.results.filePath);
								console.log(self.imageList)
							}
					 });
					}
				})
			}
		},
	}
</script>

<style>
.top {
	width: 100%;
	height: 100upx;
	background-color: #fff;
	padding: 0 30upx;
	line-height: 100upx;
	display: flex;
}
.top-l {
	width: 80upx;
	height: 80upx;
	margin-right: 20upx;
}
.top-l image {
	width: 80upx;
	height: 80upx;
	background-color: #A2A2A2;
}
.top-r {
	flex: 1;
}
.comment .grade {
	height: 80upx;
	line-height: 80upx;
	color: #F52A4C;
	background-color: #fff;
	padding: 0 30upx;
	font-size: 36upx;
}
.comment .colorG {
	color: #A2A2A2;
}
.comment .iconfont {
	font-size: 50upx;
}
.content {
	height: 240upx;
	background-color: #fff;
	padding: 30upx;
}
.content textarea {
	height: 240upx;
	padding: 10upx;
	font-size: 26upx;
}
.upload {
	background-color: #fff;
	padding: 30upx;
	overflow: hidden;
}
.upload .title {
	line-height: 80upx;
	font-size: 30upx;
}
.upload .title  text{
	font-size: 24upx;
}
.img-list .img-item{
	width: 150upx;
	height: 150upx;
	border: 1px solid #CCCCCC;
	text-align: center;
	line-height: 150upx;
	font-size: 60upx;
	margin-right: 20upx;
	float: left;
	margin-bottom: 20upx;
}
.img-list .img-item.img {
	background-color: #A2A2A2;
}
</style>
